<?php

namespace App\Repositories\Permission;

use App\Models\Role;
use App\Repositories\BaseRepository;
use Illuminate\Pagination\LengthAwarePaginator;

class RoleRepository extends BaseRepository
{
    public function __construct(Role $model)
    {
        parent::__construct($model);
    }

    public function paginate(): LengthAwarePaginator
    {
        return Role::query()->orderBy('sort')->paginate(10)->through(fn(Role $item) => [
            'id' => $item->id,
            'slug' => $item->slug,
            'name' => $item->name,
            'description' => $item->description,
            'status' => $item->status,
            'sort' => $item->sort,
            'created_at' => $item->created_at->format('Y-m-d'),
        ]);
    }

    public function getSelect(): array
    {
        return Role::query()->orderByDesc('id')->get(['id', 'name'])->toArray();
    }
}

